<template>
	<!-- groupbuy团购详情 -->
	<view class="wp">
		<!-- 分享按钮 -->
		<view @click="share"
			style="font-size: 26upx;position: fixed;right: 0;top: 550upx;background-color: #8405dc;border-radius: 20upx 0 0 20upx;color: #fff;text-align: center;z-index: 999;padding: 10upx;">分 享
			<text style="display: block;font-size: 20upx;" v-if="info.shareprice">{{info.shareprice}}</text>
			</view>
		<view class="shop_imgs">
			<swiper class="s_swiper" :circular="true" :indicator-dots="false" @change="setDot">
				<swiper-item class="swiper_item" v-for="(item,idx) in info.thumb_url" :key="idx">
					<image class="swiper_img" :src="item" @click="previewImg(info.thumb_url,idx)" mode="scaleToFill" />
				</swiper-item>
			</swiper>
			<view class="s_dots">
				<text>{{dotImg*1+1}}</text>/
				<text>{{info.thumb_url.length}}</text>
			</view>
		</view>
		<view class="s_body">
			<view class="sale">
				<view class="money">
					<text class="s_m">{{info.saleprice}}</text>
					<text class="old_m">{{info.productprice}}</text>
					<text class="label" v-if="info.mark">{{info.mark}}</text>
					<text class="label" v-if="info.limitnumstr">{{info.limitnumstr}}次</text>
				</view>
				<view class="num">已售{{info.sales}}份</view>
			</view>
			<view class="title">{{info.title}}</view>
			<!-- 门店 -->
			<view class="my_shop" @click="$navTo('/pages/shoplist/shopgoods?id='+info.supplier.uid)">
				<image :src="info.supplier.logo" mode=""></image>
				<view class="s_info">
					<view class="title clamp">{{info.supplier.supname}}</view>
					<view class="time">营业时间：{{info.supplier.saletime}}</view>
					<view class="address">
						<text class="cont clamp" selectable>{{info.supplier.supaddress}}</text>
						<view class="" @click.stop="openMap(info.supplier)">
							<uni-icons type="paperplane-filled" size="30"></uni-icons>
						</view>
					</view>
				</view>
			</view>
			<view class="block">
				<view class="title" v-if="info.timeend != '0'">
					活动有效期
				</view>
				<view style="color: #666;">【{{info.timeend}}】前可使用，过期自动退</view>
			</view>
			<view class="block">
				<view class="title">
					购买须知
				</view>
				<view class="list">
					<view style="color: #666;font-size: 24upx;line-height: 35upx;">{{info.rule}}</view>
				</view>
			</view>
			<view class="block">
				<view class="title">
					【团购套餐】
				</view>
				<view class="list" v-for="(item,idx) in info.markList" :key="idx">
					<view class="tit">{{item.title}}</view>
					<view class="row" v-for="(it,id) in item.list" :key="id">
						<text class="name">●&nbsp;&nbsp;{{it.title}}</text>
						<text class="num">({{it.num}}份)</text>
						<text class="price">￥{{it.price}}</text>
					</view>
				</view>
				<view class="list">
					<view class="tit">图片详情</view>
					<image v-for="(item,idx) in info.content" :key="idx" class="thumber" :src="item" mode="widthFix">
					</image>
				</view>
			</view>
		</view>
		<view class="sharebg" v-if="shareimg!=''" @tap="shareimg = ''">
			<!-- #ifdef APP-PLUS||MP-WEIXIN -->
			<image @longpress.stop="toSave" :src="shareimg" mode="widthFix"></image>
			<!-- #endif -->
		</view>

		<!-- 底部按钮 -->
		<uni-goods-nav class="goods-carts" :fill="true" :options="options" :button-group="customButtonGroup"
			@click="onClick" @buttonClick="$navTo('/pages/order/createOrder?type=2&id='+id+'&optionid=0&total=1')" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				dotImg: 0,
				shareimg: '',
				info: {
					buyprice: "",
					content: [],
					markList: [],
					productprice: "",
					rule: "",
					saleprice: "",
					thumb: "",
					thumb_url: [],
					title: "",
					total: "",
					timeend: "",
					sales: '',
					isfavorite: false,
					mark: '',
					shareprice:'',
					supplier: {
						logo: "",
						saletime: "",
						supaddress: "",
						supname: "",
						uid: "534"
					}
				},
				options: [{
					icon: 'star',
					text: '收藏',
				}],
				customButtonGroup: [{
					text: '立即购买',
					backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
					color: '#fff'
				}]
			}
		},
		onLoad(options) {
			if (options.id) {
				this.id = options.id;
			}
			if (options.scene) {
				let scene = decodeURIComponent(options.scene);
				this.id = this.gup('goodsid', scene);
			}
			this.getInfo();
		},
		methods: {
			getInfo() {
				this.$axios('groupgoods/goodsInfo', 'POST', 'shop', {
					id: this.id
				}).then(res => {
					if (res.data.code == 200) {
						this.info = res.data.data;
						this.options[0].icon = this.info.isfavorite ? 'star-filled' : 'star';
					}
				})
			},
			previewImg(logourl, number) {
				uni.previewImage({
					current: number,
					urls: logourl,
				});
			},
			setDot(v) {
				this.dotImg = v.detail.current + 1;
			},
			openMap(v) {
				uni.openLocation({
					latitude: parseFloat(v.lat),
					longitude: parseFloat(v.lng),
					scale: 10,
					name: v.supname,
					address: v.supaddress,
				});
			},
			share: function() {
				var that = this;
				this.$axios('detail/create_goods_poster', "POST", 'shop', {
					goodsid: that.id
				}).then(res => {
					if (res.data.code == 200) {
						that.shareimg = res.data.data.url
					}
				}, (error) => {

				})
			},
			toSave() {
				var that = this;
				uni.showModal({
					title: '图片保存',
					content: '确定要保存图片吗',
					success: e => {
						if (e['confirm']) {
							uni.downloadFile({
								url: that.shareimg,
								success: function(url) {
									uni.saveImageToPhotosAlbum({
										filePath: url.tempFilePath,
										success: function(e) {
											uni.showToast({
												title: '图片保存成功',
												icon: 'none',
												duration: 2200
											});
										},
									});
								},
								fail(e) {
									console.log(e)
								}
							});
						}
					}
				});
			},
			onClick(e) {
				if (e.index === 0) {
					this.$axios('favorite/set', "POST", 'shop', {
						id: this.id
					}).then(res => {
						if (res.data.code == 200) {
							this.info.isfavorite = res.data.data.isfavorite;
							this.options[0].icon = this.info.isfavorite ? 'star-filled' : 'star';
						}
					})


				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f8f8f8;
	}

	.wp {
		padding-bottom: 120upx;
	}

	.shop_imgs {
		position: relative;
		z-index: 100;
		// padding: 0px 0px ;
		.s_swiper {
			width: 100%;
			height: 250px;
			.swiper_img {
				width: 100%;
				// height:100%;
			}
		}

		.s_dots {
			background-color: rgba(0, 0, 0, 0.4);
			border-radius: 30upx;
			font-size: 22upx;
			padding: 10upx 20upx;
			color: #fff;
			position: absolute;
			right: 20upx;
			bottom: 50upx;
		}
	}

	.s_body {
		position: relative;
		background-color: #f8f8f8;
		border-radius: 30upx;
		top: -20px;
		z-index: 990;
		padding: 0 20upx;

		.sale {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20upx 0;

			.money {
				text {
					margin-right: 10upx;
				}

				.s_m {
					color: red;
					font-size: 46upx;

					&:before {
						content: '￥';
						font-size: 24upx;
					}
				}

				.old_m {
					color: #666;
					font-size: 22upx;
					text-decoration: line-through;

					&:before {
						content: '￥';
					}
				}

				.label {
					color: #750CD5;
					background-color: rgba(117, 12, 213, 0.2);
					font-size: 24upx;
					border-radius: 4px;
					padding: 2upx 4upx;
					letter-spacing: 1px;
					margin-right: 10upx;
				}
			}

			.num {
				color: #999;
				font-size: 24upx;
			}
		}

		.title {
			color: #000;
			font-size: 34upx;
			font-weight: bold;
			letter-spacing: 1px;
		}

		.block {
			background-color: #fff;
			border-radius: 20upx;
			padding: 20upx;
			margin-top: 20upx;

			.title {
				color: #000;
				font-size: 30upx;
				font-weight: bold;
			}

			.list {
				padding-top: 20upx;

				.tit {
					color: #000;
					font-size: 26upx;
					font-weight: bold;
				}

				.row {
					color: #303133;
					display: flex;
					align-content: center;
					font-size: 26upx;
					line-height: 60upx;

					.name {
						flex: 4;
					}

					.num {
						color: #999;
						font-size: 24upx;
						flex: 1;
						text-align: right;
					}

					.price {
						flex: 1;
						text-align: right;
					}
				}

				.thumber {
					border-radius: 20upx;
					margin-top: 20upx;
					width: 100%;
				}
			}
		}

		.my_shop {
			background: #fff;
			border-radius: 30upx;
			display: flex;
			margin-top: 20upx;
			padding: 20upx;

			image {
				border-radius: 20upx;
				height: 120upx;
				width: 120upx;
			}

			.s_info {
				padding-left: 20upx;
				line-height: 40upx;
				width: calc(100% - 130upx);

				.title {
					color: #000;
					font-weight: bold;
					letter-spacing: 1px;
				}

				.time {
					color: #666;
					font-size: 26upx;
				}
			}

			.address {
				display: flex;
				font-size: 26upx;
				align-items: center;
				justify-content: space-between;

				.cont {
					width: calc(100% - 70upx);
				}
			}
		}
	}

	.goods-carts {
		position: fixed;
		bottom: 0;
		width: 100%;
		z-index: 100;
	}

	.sharebg {
		position: fixed;
		z-index: 998;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.3);

		image {
			width: 80%;
			position: fixed;
			left: 50%;
			top: 50%;
			z-index: 999;
			transform: translate(-50%, -50%);
		}
	}
</style>